<template>
	<view class="padding32">
		<u-navbar titleStyle="font-size:40rpx;color:#333" :placeholder='true' title="发布评价" :autoBack="true">
			<view class="btnClick1 cof bgcred borderred" slot="right" @click="submit"
				style="height: 60rpx ;box-shadow: 0px 5rpx 8rpx 1rpx rgba(255, 111, 111, 0.25);">
				发布
			</view>
		</u-navbar>

		<view class="" v-for="(item,index) in goods" :key="index">
			<view class="whiteBox mb24">
				<view class="flex">
					<u-image :src="item.image" :lazy-load="true" height="96rpx" width="96rpx" radius='8rpx'
						style='margin-right: 12rpx;' >
					</u-image>
					<view class="" style="width: 80%;">
						<view class="elipes1">
							{{item.goods_name}}
						</view>
						<view class="co9 fontS24 flex" style="margin-top: 20rpx;">
							<view class=" ">
								规格:{{item.details}}
							</view>
							<view class="" style="margin-left: 40rpx;">
								数量:x{{item.product_num}}
							</view>
						</view>
					</view>
				</view>
				<view class="mb32 mt32 flex">   
					<view class="co9">
						相符描述：
					</view>  
					<view class="">
						<u-rate count="5" v-model="info[index].start" :minCount="1"></u-rate>
					</view>
				</view>
				<u-textarea confirmType='done' v-model="info[index].comment_text" placeholder="从多个角度评价宝贝，可以帮助更多想买的人"
					count autoHeight maxlength='200' style='min-height: 242rpx;' placeholderClass="fontS24">
				</u-textarea>
				<!-- 评价图片 -->
				<view class="flex mt24" style="flex-wrap: wrap;">
					<view class="relative" v-for="(itemm,indexx) in  image[index] " style="margin:0 10rpx 10rpx 0rpx;">
						<view class="absolute" style="top: -15rpx;right: 0;z-index: 9;" @click="del(indexx,index)">
							<u-icon name="close-circle" :color="$store.state.homeRed" size="30rpx"></u-icon>
						</view>
						<image :src="itemm" mode=""  style="width: 140rpx;height:140rpx;border-radius: 8rpx;">
						</image>
					</view>
					<view class="iamgbox flexcenter pa" @click="upImg(index)" style="margin:0 10rpx 10rpx 0rpx;">
						<image src="../../../../static/images/mine/Frame.png" mode=""
							style="width: 48rpx;height: 48rpx;">
						</image>
						<view class="fontS24">
							图片
						</view>
					</view>
					<view class="iamgbox flexcenter pa" @click="upImg(index)" style="margin:0 10rpx 10rpx 0rpx;">
						<image src="../../../../static/images/mine/Frame.png" mode=""
							style="width: 48rpx;height: 48rpx;">
						</image>
						<view class="fontS24">
							视频
						</view>
					</view>
				</view>
				<view class="flex" style="margin-top: 20rpx;">
					<view class="box flexCenter" :class="!info[index].status?'box1':''" @click="info[index].status=info[index].status==1?0:1">
						<u-icon name='checkbox-mark' color="#fff" size="30rpx"  ></u-icon> 
					</view>
					<view class="co9"><text class="co3 fontS28" style="margin-right: 12rpx;">匿名</text>(隐藏头像昵称)
					</view> 
					<!-- <u-radio-group v-model="info[index].status" placement="column">
						<view class="flex">
							<view class="">
								<u-radio name="1" inactiveColor="#d9d9d9" activeColor="#dd2131" shape="square"></u-radio>
							</view>
							<view class="co9"><text class="co3 fontS28" style="margin-right: 12rpx;">匿名</text>(隐藏头像昵称)
							</view>
						</view>
					</u-radio-group> -->
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods: [],
				data: [],
				info: [],
				value: '',
				store_id: "",
				image:[],
			}
		},
		methods: {
			
			// 删除图片
			del(indexx,index){
				this.image[index].splice(indexx,1)
			},
			//发表评价 
			submit(){
				this.image.forEach((item,index)=>{
					let a=item.join(',')
					this.info[index].image=a
				})
				this.$my.post('/index/orderComment/addComment', {
					data: JSON.stringify(this.info),
					sub_order_id: this.sub_order_id,
					store_id: this.store_id,
				}).then(res => {
					this.$my.toast(res.message)
					if (res.code == 200) {
						this.$my.go('',500)
					}
				})
			},
		  upImg(index) {
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera '], //手机拍照
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						tempFilePaths.forEach(item=>{
							uni.uploadFile({
								url: this.$my.url + '/index/com/file',
								filePath: item,
								name: 'file',
								header: {
									"Accept-Language": uni.getStorageSync('locale') ? uni.getStorageSync('locale') : 'zh',
									'token': uni.getStorageSync('token'),
								},
								formData: {
									"file": tempFilePaths[0],
									use: 'company_photo'
								},
								success: (uploadFileRes) => {
									let res = JSON.parse(uploadFileRes.data);
									if (res.code == 200) {
										this.image[index].push(res.data.file_path)
										console.log(res.data)
										// this.toast(res.message)
										// resolve(res.data)
									} else {
										// this.toast(res.message)
									}
								}
							});
						})
					}
				});
			},
			init() {
				this.$my.post('/index/orderComment/findToEvaluateList', {
					sub_order_id: this.sub_order_id
				}).then(res => {
					if (res.code == 200) {
						this.goods = res.data.orderProduct
						this.store_id = res.data.store_id
						console.log(res.data)
						this.newarr()
					}
				})
			},
			newarr() {
				for (let a = 0; a < this.goods.length; a++) {
					let item = {
						product_id: this.goods[a].product_id,
						start: 4,
						order_product_id: this.goods[a].order_product_id,
						comment_text: "",
						status: 1,
						image:'',
					}
					//["http://jinceshishi.oss-cn-beijing.aliyuncs.com/static/20221104/478526825cbba3a37f8ca9282678a955.png","http://jinceshishi.oss-cn-beijing.aliyuncs.com/static/20221104/c3335cf7ef5b5991f71db8ab56f048ae.png"]
					let item1=[]
					
					this.info.push(item)
					this.info.forEach(item=>{
						this.$set(item,'status',1)
					})
					this.image.push(item1)
				}
				console.log(this.image)
			},
			
		},
		onLoad(option) {
			this.sub_order_id = option.sub_order_id
			console.log(this.sub_order_id, '传递');
			this.init()
			// console.log(option.sub_order_id);
		}
	}
</script>

<style lang="scss" scoped>
	.box{
		width: 35rpx;
		height: 35rpx;
		border:2rpx solid #CCCCCC;
		border-radius: 8rpx;
		margin-right: 10rpx;
		padding-left: 2rpx;
		box-sizing: border-box;
	}
	.box1{
		background-color: #DD2131;
		border-color: #DD2131;
		text-align: center;
	}
	.iamgbox {
		width: 159rpx;
		height: 159rpx;
		text-align: center;
		display: flex;
		border: 1rpx solid #CCCCCC;
		border-radius: 8rpx;
		justify-content: space-between;
		padding: 32rpx 0;
		box-sizing: border-box;
	}

	.whiteBox {
		margin-bottom: 24rpx;

	}
</style>
